package com.zmn.plat.admin.controller.orderconfig.returnvisit.category;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import com.zmn.common.dictionary.GlobalDict;
import com.zmn.plat.model.entity.orderconfig.returnvisitcontent.ReturnVisitCategory;
import com.zmn.plat.model.entity.orderconfig.returnvisitcontent.ReturnVisitCategoryQuery;

/**
 * 类描述:回访类别列表控制器
 *
 * @author linfeng
 * @since 2020/04/15/14:46
 */
@Controller
@RequestMapping(value = "/orderconfig/returnvisit/category/")
public class ReturnVisitCategoryListController extends ReturnVisitCategoryBaseController {
    private Logger logger = LoggerFactory.getLogger(ReturnVisitCategoryListController.class);

    @RequestMapping(value = "list")
    @RequiresPermissions("/orderconfig/returnvisit/category/list.action")
    public ModelAndView list(@ModelAttribute ReturnVisitCategoryQuery query) {
        List<ReturnVisitCategory> items = returnVisitCategoryService.listPageByQuery(query);

        ModelAndView mav = new ModelAndView("orderconfig/returnvisit/category/list");
        mav.addObject("vo", query);
        mav.addObject("items", items);

        return mav;
    }

    @RequestMapping(value = "detail")
    @RequiresPermissions("/orderconfig/returnvisit/category/detail.action")
    public ModelAndView detail(@RequestParam(value = "id", defaultValue = "0") Integer id) {
        ReturnVisitCategory returnVisitCategory;
        if (id > 0) {
            returnVisitCategory = returnVisitCategoryService.findById(id);
        } else {
            returnVisitCategory = new ReturnVisitCategory();
        }

        if (returnVisitCategory.getSort() == null) {
            Integer sort = returnVisitCategoryService.findMaxSort();
            sort = sort == null ? 1 : sort + 1;
            returnVisitCategory.setSort(sort);
        }

        ModelAndView mav = new ModelAndView("orderconfig/returnvisit/category/detail");

        mav.addObject("statuses", GlobalDict.getStatusList(false));
        mav.addObject("vo", id);
        mav.addObject("returnvisitcategory", returnVisitCategory);
        return mav;
    }
}
